<?php

namespace Modules\Shop\Http\Controllers;

use HiCommon\Service\AccountSettleService;
use Illuminate\Support\Facades\Request;

class AccountSettleController extends BaseController
{
    /******************************************** 订单结算 ********************************************/

    /*商户-订单结算列表*/
    public function order_index(){
        try {
            $arr_input = Request::input();
            $arr_input['shop_id'] = shop_shop_id();
            $result = AccountSettleService::get_settle_order_list_for_shop($arr_input);
            $arr_data = $result['data'];
            echo_error($result);

            $result = AccountSettleService::get_settle_order_info_for_shop($arr_input['shop_id']);
            $arr_data['settle_data'] = $result['data'];
            echo_error($result);
            return view('shop::account_settle.index', $arr_data);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*商户-订单结算-添加页面*/
    public function order_add_page(){
        try {
            $n_shop_id = shop_shop_id();
            $result = AccountSettleService::api_find_settle($n_shop_id);
            echo_error($result);
            $arr_data = [
              'arr_data'=>$result['data'],
              'arr_account_type'=>[
                'ali'=>'支付宝',
                'bank'=>'银行卡',
              ],
            ];
            return view('shop::account_settle.add_page',$arr_data);
        }
        catch (\Exception $exception) {
            msg_error('fail-'.$exception->getMessage());
            return 'ok';
        }
    }

    /*商户-订单结算-添加操作*/
    public function order_add(){
        try {
            $arr_input = Request::input();

            //修改
            shiwu_start();
            $arr_input['shop_id'] = shop_shop_id();
            $result = AccountSettleService::api_shop_add_one($arr_input);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*商户-订单结算-编辑页面*/
    public function order_edit_page(){
        try {
            $n_id = intval(Request::input('id',0));
            $result = AccountSettleService::api_find_one($n_id);
            echo_error($result);
            $arr_data = [
              'arr_data'=>$result['data'],
              'arr_account_type'=>[
                'ali'=>'支付宝',
                'bank'=>'银行卡',
              ],
            ];
            return view('shop::account_settle.edit_page',$arr_data);
        }
        catch (\Exception $exception) {
            msg_error('fail-'.$exception->getMessage());
            return 'ok';
        }
    }

    /*商户-订单结算-编辑操作*/
    public function order_edit(){
        try {
            $arr_input = Request::input();

            //修改
            shiwu_start();
            $result = AccountSettleService::api_shop_edit_one($arr_input);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*商户-订单结算-提交*/
    public function order_submit_settle(){
        try {
            $n_id = intval(Request::input('id',0));

            //提交
            shiwu_start();
            $result = AccountSettleService::api_submit_settle($n_id);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }



    /******************************************** 优惠券津贴结算 ********************************************/

    /*商户-优惠券津贴结算列表*/
    public function coupon_index(){
        try {
            $arr_input = Request::input();
            $arr_input['shop_id'] = shop_shop_id();
            $result = AccountSettleService::get_settle_coupon_list_for_shop($arr_input);
            $arr_data = $result['data'];
            echo_error($result);

            $result = AccountSettleService::get_settle_coupon_info_for_shop($arr_input['shop_id']);
            $arr_data['settle_data'] = $result['data'];
            echo_error($result);
            return view('shop::account_settle.coupon_index', $arr_data);
        }
        catch (\Exception $exception) {
            return hello_error('失败-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*商户-优惠券津贴结算-添加页面*/
    public function coupon_add_page(){
        try {
            $n_shop_id = shop_shop_id();
            $result = AccountSettleService::api_find_settle_coupon($n_shop_id);
            echo_error($result);
            $arr_data = [
              'arr_data'=>$result['data'],
              'arr_account_type'=>[
                'ali'=>'支付宝',
                'bank'=>'银行卡',
              ],
            ];
            return view('shop::account_settle.coupon_add_page',$arr_data);
        }
        catch (\Exception $exception) {
            msg_error('fail-'.$exception->getMessage());
            return 'ok';
        }
    }

    /*商户-优惠券津贴结算-添加操作*/
    public function coupon_add(){
        try {
            $arr_input = Request::input();

            //修改
            shiwu_start();
            $arr_input['shop_id'] = shop_shop_id();
            $result = AccountSettleService::api_shop_settle_coupon_add_one($arr_input);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*商户-优惠券津贴结算-编辑页面*/
    public function coupon_edit_page(){
        try {
            $n_id = intval(Request::input('id',0));
            $result = AccountSettleService::api_find_one($n_id);
            echo_error($result);
            $arr_data = [
              'arr_data'=>$result['data'],
              'arr_account_type'=>[
                'ali'=>'支付宝',
                'bank'=>'银行卡',
              ],
            ];
            return view('shop::account_settle.coupon_edit_page',$arr_data);
        }
        catch (\Exception $exception) {
            msg_error('fail-'.$exception->getMessage());
            return 'ok';
        }
    }

    /*商户-优惠券津贴结算-编辑操作*/
    public function coupon_edit(){
        try {
            $arr_input = Request::input();

            //修改
            shiwu_start();
            $result = AccountSettleService::api_shop_edit_one($arr_input);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

    /*商户-优惠券津贴结算-提交*/
    public function coupon_submit_settle(){
        try {
            $n_id = intval(Request::input('id',0));

            //提交
            shiwu_start();
            $result = AccountSettleService::api_submit_settle($n_id);
            shiwu_end($result);

            return  $result;
        }
        catch (\Exception $exception) {
            return hello_error('fail-'.$exception->getMessage(),[],$exception->getMessage());
        }
    }

}
